package de.unihannover.se.restlab.microblog.data;

import javax.naming.InitialContext;
import javax.naming.NamingException;

public abstract class AbstractStorage {

	
	// Implement this method! i.e.:
	//    public static UserStorage getStorage() {
	//    	return (UserStorage) getConcreteStorage(UserStorage.class);
	//    }
	
	/*
	public abstract static AbstractStorage getStorage() throws Exception {
		throw new Exception("Not Yet Implemented");
	}
	*/

	protected static AbstractStorage getConcreteStorage(Class<?> clazz) {
		
		javax.naming.Context context = null;
		try { 
			return (AbstractStorage) new InitialContext().lookup("java:module/" + clazz.getSimpleName());
		} catch (NamingException e) {
			e.printStackTrace();
		} finally {
			try {
				if (context != null)
					context.close();
			} catch (NamingException e) {
				e.printStackTrace();
			}
		}
		return null;
	}

}
